package com.tianji.learning.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tianji.learning.domain.po.LearningRecord;
import com.tianji.learning.domain.po.PointsRecord;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface PointsRecordMapper extends BaseMapper<PointsRecord> {
    // 查询今日已得积分
    @Select("select ifnull(sum(points),0) from points_record where user_id=#{userId} and type=#{type} and create_time between " +
            "#{begin} adn #{end}")
    Integer findPoints(Long userId, int value, LocalDateTime begin, LocalDateTime end);

    //分组统计我今天获得的积分
    @Select("select type,ifnull(sum(points),0) points from points_record WHERE user_id=#{userId} and" +
            "create_time BETWEEN #{begin} AND #{end} GROUP BY TYPE")
    List<PointsRecord> queryMyTodayPoints(Long user, LocalDateTime begin, LocalDateTime end);
}
